package cn.itcast.controller;

import cn.itcast.domain.Courier;

import cn.itcast.domain.Standard;
import cn.itcast.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

import java.util.Map;

@Controller
public class CourierController {
    @Autowired
    private CourierService courierService;



    @RequestMapping("/courier_save")
    public String save(Courier courier){
        courierService.save(courier);
        return "redirect:/pages/base/courier.html";
    }

    @RequestMapping("/courier_pageQuery")
    @ResponseBody
    public Map pageQuery(int page, int rows){
        System.out.println("page="+page+",rows="+rows);
        Page<Courier> pageResult = courierService.pageQuery(page, rows);
        HashMap<String, Object> result = new HashMap<>();
        result.put("total",pageResult.getTotalElements());
        result.put("rows",pageResult.getContent());
        return result;
    }

    @RequestMapping("/courier_delBatch")
    public String delBatch(String[] ids){
        courierService.delBatch(ids);
        return "redirect:/pages/base/courier.html";
    }

    @RequestMapping("/courier_restore")
    public String restore(String[] ids){
        courierService.restore(ids);
        return "redirect:/pages/base/courier.html";
    }



}
